﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CMS.Web.UI;

using TRPOP.CMS.Message;
using TRPOP.CMS.Message.model;
using TRPOP.CMS.Message.UI;

namespace TRPOP.CMS.Web.cms.Message
{
    public partial class messagereply_save :BaseAdmin
    {

        #region 页面属性
        protected IMessage m_IMessage = MessageAccess.GetInstance();
        protected int intMessageID = 0;
        protected string strReplyName = "";//回复人姓名，默认为系统登陆者昵称，可修改
        protected MessageInfo oMessageInfo = new MessageInfo();
        protected string strMessageName = string.Empty;
        protected string strMessageContent = string.Empty;
        #endregion
        
        #region 页面事件
        protected void Page_Load(object sender, EventArgs e)
        {
            intMessageID = RequestHelper.RequestInt("id");
            LoadBase();
            if (!IsPostBack)
            {
                strReplyName = base.mUserBaseInfo.Name;
                txtReplyName.Text = strReplyName;
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (intMessageID > 0)
            {
                if (String.IsNullOrEmpty(txtReplyContent.Text))
                {
                    Alert("回复内容不能为空");
                    return;
                }
                if (String.IsNullOrEmpty(txtReplyName.Text))
                {
                    txtReplyName.Text = base.mUserBaseInfo.Name;
                }
                MessageReplyInfo oInfo = new MessageReplyInfo();

                oInfo.iMessageID = intMessageID;
                oInfo.iMessageReplyID = 0;
                oInfo.dtMessageReplyTime = DateTime.Now;
                oInfo.nvcMessageReplyTitle = txtReplytitle.Text.Trim();
                oInfo.ntMessageReplyContent =txtReplyContent.Text.Trim();
                oInfo.nvcMessageReplyUserName = txtReplyName.Text.Trim();
                oInfo.iDisplayOrder = 0;//排序字段暂定为0

                if (m_IMessage.SaveMessageReply(oInfo))
                {
                    Alert("留言回复成功！", "message_list.aspx");
                }
                else
                {
                    Alert("留言回复失败！");
                }
            }
        }
        #endregion

        #region
        public void LoadBase()
        {
            if (ViewState["MessageInfo"] != null)
            {
                oMessageInfo = ViewState["MessageInfo"] as MessageInfo;
            }
            else
            {
                oMessageInfo = m_IMessage.GetMessageInfo(RequestHelper.RequestInt("id"));
                if (oMessageInfo == null)
                    oMessageInfo = new MessageInfo();
            }
        }
        #endregion
    }
}